/**
 * Created by 小敏哥 on 2017/11/1.
 *广告弹窗内容部分
 */
import React, {Component} from 'react';
import style from './index.scss';

class ADDialog extends Component {
    constructor(props) {
        super(props);
        this.state = {
            mainClass: style.adDialog + ' ' + style.hide
        };
        ADDialog.show = ADDialog.show.bind(this);
    }

    //全局方法，显示
    static show() {
        this.setState({
            mainClass: style.adDialog
        })
    }

    //关闭
    close() {
        this.setState({
            mainClass: style.adDialog + ' ' + style.hide
        })
    }

    go() {
        this.close();
        this.props.url && (location.href = this.props.url);
    }

    render() {
        return <div className={this.state.mainClass}>
            <div className={style.content}>
                <img src={this.props.imgUrl} onClick={() => {
                    this.go()
                }}/>
                <button onClick={() => {
                    this.close()
                }}><img src="./images/closeAD.png"/></button>
            </div>
        </div>
    }
}

//使用context
ADDialog.contextTypes = {
    router: React.PropTypes.object.isRequired
};

export default ADDialog
